<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>自定义扩展 | d2-crud-plus</title>
    <meta name="generator" content="VuePress 1.5.2">
    <link rel="icon" href="/d2-crud-plus/icon-only.png">
    <link rel="manifest" href="/d2-crud-plus/manifest.json">
    <link rel="apple-touch-icon" href="/d2-crud-plus/icons/apple-touch-icon-152x152.png">
    <link rel="mask-icon" href="/d2-crud-plus/icons/safari-pinned-tab.svg" color="#3eaf7c">
    <meta name="description" content="d2-crud-plus doc">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/icons/msapplication-icon-144x144.png">
    <meta name="msapplication-TileColor" content="#000000">
    <link rel="preload" href="/d2-crud-plus/assets/css/0.styles.094573b2.css" as="style"><link rel="preload" href="/d2-crud-plus/assets/js/app.920fe806.js" as="script"><link rel="preload" href="/d2-crud-plus/assets/js/2.9f3ba775.js" as="script"><link rel="preload" href="/d2-crud-plus/assets/js/50.5a933b10.js" as="script"><link rel="prefetch" href="/d2-crud-plus/assets/js/10.768312da.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/11.88f0302a.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/12.0a517745.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/13.a305030c.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/14.d7129909.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/15.1ff1eab0.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/16.b84cb74e.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/17.0e17fa97.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/18.b4667ec6.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/19.4a1d2603.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/20.e542b5eb.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/21.bea29276.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/22.5834f6ce.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/23.d514eada.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/24.10003849.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/25.238b33f6.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/26.64d5f744.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/27.20999cf2.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/28.a0ae569e.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/29.958d25f6.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/3.6fc0af51.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/30.5daeb87d.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/31.8f2a2581.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/32.bf1a9e00.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/33.fb5669a4.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/34.38bf074e.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/35.4789523c.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/36.5e0ded16.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/37.8b00f742.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/38.49c29967.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/39.f40a50c6.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/4.6d40d8fb.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/40.6422ce3c.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/41.76e6d756.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/42.2571374a.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/43.0e62c77f.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/44.59d7ad10.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/45.81bb2ffe.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/46.712a33f6.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/47.6a6f286c.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/48.25afab63.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/49.f6fd43e8.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/5.8571b144.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/51.fff19aba.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/52.5b7aa258.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/53.e207b0e8.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/54.c28e9900.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/55.23098b29.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/56.dd2936c0.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/57.e7938457.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/58.d206d759.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/59.066b3e6d.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/6.8660d829.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/60.f55b15a6.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/61.9c91c70f.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/62.bf4ab90c.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/63.1ba8b586.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/64.53572d02.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/65.ba75d2b6.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/66.3b137930.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/67.3f157fd4.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/68.f1e28a8c.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/69.b8844926.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/7.d8550247.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/70.bb6afb7e.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/71.aa8ba6ae.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/8.b8c6f50a.js"><link rel="prefetch" href="/d2-crud-plus/assets/js/9.bb5c3b5b.js">
    <link rel="stylesheet" href="/d2-crud-plus/assets/css/0.styles.094573b2.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/d2-crud-plus/" class="home-link router-link-active"><!----> <span class="site-name">d2-crud-plus</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/d2-crud-plus/guide/" class="nav-link router-link-active">
  指南
</a></div><div class="nav-item"><a href="http://qiniu.veryreader.com/D2CrudPlusExample/index.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  演示
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <a href="https://github.com/greper/d2-crud-plus" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/d2-crud-plus/guide/" class="nav-link router-link-active">
  指南
</a></div><div class="nav-item"><a href="http://qiniu.veryreader.com/D2CrudPlusExample/index.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  演示
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <a href="https://github.com/greper/d2-crud-plus" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/d2-crud-plus/guide/" class="sidebar-link">介绍</a></li><li><a href="/d2-crud-plus/guide/quickstart.html" class="sidebar-link">快速上手</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>进阶</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/d2-crud-plus/guide/mixins.html" class="sidebar-link">d2CrudPlus.crud</a></li><li><a href="/d2-crud-plus/guide/options.html" class="sidebar-link">crud配置项</a></li><li><a href="/d2-crud-plus/guide/structure.html" class="sidebar-link">数据结构</a></li><li><a href="/d2-crud-plus/guide/component.html" class="sidebar-link">组件配置</a></li><li><a href="/d2-crud-plus/guide/column-type.html" class="sidebar-link">字段类型</a></li><li><a href="/d2-crud-plus/guide/types.html" class="sidebar-link">字段类型列表</a></li><li><a href="/d2-crud-plus/guide/slot.html" class="sidebar-link">slot自定义</a></li><li><a href="/d2-crud-plus/guide/extends.html" class="active sidebar-link">自定义扩展</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#开发一个自定义扩展" class="sidebar-link">开发一个自定义扩展</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#_1-自定义一个表单组件" class="sidebar-link">1. 自定义一个表单组件</a></li><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#_2-自定义一个行展示组件" class="sidebar-link">2. 自定义一个行展示组件</a></li><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#_3-定义字段类型" class="sidebar-link">3. 定义字段类型</a></li><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#_4-打包成组件包" class="sidebar-link">4. 打包成组件包</a></li><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#_5-在项目中安装" class="sidebar-link">5. 在项目中安装</a></li><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#_6-使用" class="sidebar-link">6. 使用</a></li></ul></li><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#d2p-extends（现有自定义扩展）" class="sidebar-link">d2p-extends（现有自定义扩展）</a></li><li class="sidebar-sub-header"><a href="/d2-crud-plus/guide/extends.html#扩展组件懒加载" class="sidebar-link">扩展组件懒加载</a></li></ul></li><li><a href="/d2-crud-plus/guide/dict.html" class="sidebar-link">数据字典</a></li><li><a href="/d2-crud-plus/guide/event.html" class="sidebar-link">事件监听</a></li><li><a href="/d2-crud-plus/guide/flat-data.html" class="sidebar-link">数据扁平化</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>附加功能</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/d2-crud-plus/guide/permission.html" class="sidebar-link">权限管理</a></li><li><a href="/d2-crud-plus/guide/generate.html" class="sidebar-link">代码生成</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>更多帮助</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/d2-crud-plus/guide/upgrade.html" class="sidebar-link">版本升级</a></li><li><a href="/d2-crud-plus/guide/breakingchange.html" class="sidebar-link">版本变更说明</a></li><li><a href="/d2-crud-plus/guide/questions.html" class="sidebar-link">常见问题</a></li><li><a href="/d2-crud-plus/guide/contact.html" class="sidebar-link">联系作者</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>extends文档</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/d2-crud-plus/guide/extends/area-selector.html" class="sidebar-link">省市区选择组件</a></li><li><a href="/d2-crud-plus/guide/extends/avatar-cropper.html" class="sidebar-link">头像裁剪上传</a></li><li><a href="/d2-crud-plus/guide/extends/file-uploader.html" class="sidebar-link">文件上传组件</a></li><li><a href="/d2-crud-plus/guide/extends/full-editor.html" class="sidebar-link">富文本</a></li><li><a href="/d2-crud-plus/guide/extends/icon-selector.html" class="sidebar-link">icon选择组件</a></li><li><a href="/d2-crud-plus/guide/extends/tree-selector.html" class="sidebar-link">树形选择组件</a></li><li><a href="/d2-crud-plus/guide/extends/uploader.html" class="sidebar-link">文件上传lib</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>组件文档</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>ChangeLog</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="自定义扩展"><a href="#自定义扩展" class="header-anchor">#</a> 自定义扩展</h1> <p>您还可以自定义类型扩展，将自定义类型、自定义表单组件、自定义行展示组件整合为一个模块</p> <h2 id="开发一个自定义扩展"><a href="#开发一个自定义扩展" class="header-anchor">#</a> 开发一个自定义扩展</h2> <p>此处以<a href="https://github.com/greper/d2-crud-plus/tree/master/packages/d2-crud-plus-extends/src/demo-extend" target="_blank" rel="noopener noreferrer">demo-extend<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>
为例来展示如何开发一个自定义扩展</p> <h3 id="_1-自定义一个表单组件"><a href="#_1-自定义一个表单组件" class="header-anchor">#</a> 1. 自定义一个表单组件</h3> <p>这个表单组件需要符合<code>v-model</code>写法，具体请参考<a href="https://cn.vuejs.org/v2/guide/components-custom-events.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9A%84-v-model" target="_blank" rel="noopener noreferrer">vue文档<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a><br>
简单来说就是要能通过value属性输入值，并且通过input、change等事件返回改变后的值</p> <div class="language-vue extra-class"><pre class="language-vue"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-tag</span> <span class="token attr-name">:type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>color<span class="token punctuation">&quot;</span></span> <span class="token punctuation">&gt;</span></span>您点击了:  {{currentValue}}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-tag</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-button</span> <span class="token attr-name">:diabled</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>disabled || readonly<span class="token punctuation">&quot;</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>d2-ml-5<span class="token punctuation">&quot;</span></span> <span class="token attr-name">@click</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>doClick('1')<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>点击1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-button</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-button</span> <span class="token attr-name">:diabled</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>disabled || readonly<span class="token punctuation">&quot;</span></span> <span class="token attr-name">@click</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>doClick('2')<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>点击2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-button</span><span class="token punctuation">&gt;</span></span>
    插槽：<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slot</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>test1<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>1<span class="token punctuation">&quot;</span></span><span class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
<span class="token comment">// 表单扩展组件示例</span>
<span class="token comment">// 需要符合v-model的写法</span>
<span class="token comment">// 简单来说就是，接收value参数，当用户对value进行改变时，通过input通知父组件修改value的值。</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  name<span class="token punctuation">:</span> <span class="token string">'d2p-form-input'</span><span class="token punctuation">,</span>
  props<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// 值</span>
    value<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      type<span class="token punctuation">:</span> String<span class="token punctuation">,</span>
      required<span class="token punctuation">:</span> <span class="token boolean">false</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// 禁用</span>
    disabled<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      type<span class="token punctuation">:</span> <span class="token punctuation">[</span>Boolean<span class="token punctuation">]</span><span class="token punctuation">,</span>
      required<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
      <span class="token keyword">default</span><span class="token punctuation">:</span> <span class="token boolean">false</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// 只读</span>
    readonly<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      type<span class="token punctuation">:</span> <span class="token punctuation">[</span>Boolean<span class="token punctuation">]</span><span class="token punctuation">,</span>
      required<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
      <span class="token keyword">default</span><span class="token punctuation">:</span> <span class="token boolean">false</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// 你可以定义一些参数，通过component.props传进来</span>
    color<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      required<span class="token punctuation">:</span> <span class="token boolean">false</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span>
      <span class="token comment">// 本组件的实际value值</span>
      <span class="token comment">// 由于value值是props参数，是不允许修改的，需要用别的值存起来</span>
      currentValue<span class="token punctuation">:</span> <span class="token string">''</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  computed<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// 你也可以通过computed来监听value的变化，跟watch作用类似，根据实际情况选用</span>
    <span class="token comment">// currentValue () {</span>
    <span class="token comment">//   return this.value</span>
    <span class="token comment">// }</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  watch<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token function">value</span> <span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">// 父组件收到input事件后会通过v-model改变value参数的值</span>
      <span class="token comment">// 然后此处会watch到value的改变，发出change事件</span>
      <span class="token comment">// change事件放在此处发射的好处是，当外部修改value值时，也能够触发form-data-change事件</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$emit</span><span class="token punctuation">(</span><span class="token string">'change'</span><span class="token punctuation">,</span> value<span class="token punctuation">)</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>currentValue <span class="token operator">===</span> value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span>
      <span class="token punctuation">}</span>
      <span class="token comment">// 如果值是被外部改变的，则修改本组件的currentValue</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setValue</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">created</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 给currentValue设置初始值</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setValue</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>value<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">mounted</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'demo-input'</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>$slots<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token function">setValue</span> <span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">// 在这里对 传入的value值做处理</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>currentValue <span class="token operator">=</span> value
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// 用户触发按钮点击</span>
    <span class="token function">doClick</span> <span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">// 发出input事件通知父组件，然后请看上面watch的注释 ↑↑↑↑</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$emit</span><span class="token punctuation">(</span><span class="token string">'input'</span><span class="token punctuation">,</span> value<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h3 id="_2-自定义一个行展示组件"><a href="#_2-自定义一个行展示组件" class="header-anchor">#</a> 2. 自定义一个行展示组件</h3> <blockquote><p>d2-crud-plus舍弃了column.component的行编辑功能，将column.component作为了行展示组件使用</p></blockquote> <p>该组件也需要符合<code>v-model</code>写法，由于是展示组件，无需发送input和change事件<br>
但要求能够感知传入的value值的变化<br>
所以必须通过watch或者computed方式来根据value变化而改变展示结果</p> <div class="language-vue extra-class"><pre class="language-vue"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-tag</span> <span class="token attr-name">:type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>color<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>您选择了-&gt; {{value}}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-tag</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
<span class="token comment">// 本示例是行展示组件的最简版本</span>
<span class="token comment">// 如果要对值做一些处理后再展示，请看index-advance.vue版本</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  name<span class="token punctuation">:</span> <span class="token string">'d2p-row-format'</span><span class="token punctuation">,</span>
  props<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// 接收row.xxx的值</span>
    value<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      type<span class="token punctuation">:</span> String<span class="token punctuation">,</span>
      required<span class="token punctuation">:</span> <span class="token boolean">false</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    color<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      require<span class="token punctuation">:</span> <span class="token boolean">false</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h3 id="_3-定义字段类型"><a href="#_3-定义字段类型" class="header-anchor">#</a> 3. 定义字段类型</h3> <p>你也可以直接使用已注册的符合v-model的其他组件组合使用</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token comment">// 字段类型配置，注册之后即可在crud.js中使用了</span>
  <span class="token string">'demo-extend'</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// 表单组件配置</span>
    form<span class="token punctuation">:</span> <span class="token punctuation">{</span> component<span class="token punctuation">:</span> <span class="token punctuation">{</span> name<span class="token punctuation">:</span> <span class="token string">'d2p-form-input'</span><span class="token punctuation">,</span> props<span class="token punctuation">:</span> <span class="token punctuation">{</span> color<span class="token punctuation">:</span> <span class="token string">'danger'</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// 行组件配置</span>
    component<span class="token punctuation">:</span> <span class="token punctuation">{</span> name<span class="token punctuation">:</span> <span class="token string">'d2p-row-format'</span><span class="token punctuation">,</span> props<span class="token punctuation">:</span> <span class="token punctuation">{</span> color<span class="token punctuation">:</span> <span class="token string">'success'</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// 行展示时居中</span>
    align<span class="token punctuation">:</span> <span class="token string">'center'</span>
    <span class="token comment">// 您还可以写更多默认配置</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h3 id="_4-打包成组件包"><a href="#_4-打包成组件包" class="header-anchor">#</a> 4. 打包成组件包</h3> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> d2CrudPlus <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'../utils/d2-crud-plus'</span>
<span class="token keyword">import</span> types <span class="token keyword">from</span> <span class="token string">'./types'</span>

<span class="token keyword">function</span> <span class="token function">install</span> <span class="token punctuation">(</span><span class="token parameter">Vue<span class="token punctuation">,</span> options</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  Vue<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span><span class="token string">'d2p-form-input'</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'./lib/d2p-form-input'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  Vue<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span><span class="token string">'d2p-row-format'</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'./lib/d2p-row-format'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>d2CrudPlus <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 注册字段类型`demo-extend`</span>
    d2CrudPlus<span class="token punctuation">.</span>util<span class="token punctuation">.</span>columnResolve<span class="token punctuation">.</span><span class="token function">addTypes</span><span class="token punctuation">(</span>types<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// 导出install， 通过`vue.use(D2pDemoExtend)`安装后 ，`demo-extend` 就可以在`crud.js`中使用了</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  install
<span class="token punctuation">}</span>
</code></pre></div><h3 id="_5-在项目中安装"><a href="#_5-在项目中安装" class="header-anchor">#</a> 5. 在项目中安装</h3> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> D2pDemoExtend <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'d2p-extends'</span> 
Vue<span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>D2pDemoExtend<span class="token punctuation">)</span>
</code></pre></div><h3 id="_6-使用"><a href="#_6-使用" class="header-anchor">#</a> 6. 使用</h3> <p><a href="http://qiniu.veryreader.com/D2CrudPlusExample/index.html#/demo/form/slot" target="_blank" rel="noopener noreferrer">查看效果<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">export</span> <span class="token keyword">const</span> crudOptions <span class="token operator">=</span> <span class="token punctuation">{</span>
  columns<span class="token punctuation">:</span> <span class="token punctuation">[</span>
     <span class="token punctuation">{</span>
      title<span class="token punctuation">:</span> <span class="token string">'自定义组件'</span><span class="token punctuation">,</span>
      key<span class="token punctuation">:</span> <span class="token string">'demo'</span><span class="token punctuation">,</span>
      type<span class="token punctuation">:</span> <span class="token string">'demo-extend'</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span> 
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="d2p-extends（现有自定义扩展）"><a href="#d2p-extends（现有自定义扩展）" class="header-anchor">#</a> d2p-extends（现有自定义扩展）</h2> <p><a href="https://github.com/greper/d2-crud-plus/tree/master/packages/d2-crud-plus-extends" target="_blank" rel="noopener noreferrer">d2p-extends<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <h2 id="扩展组件懒加载"><a href="#扩展组件懒加载" class="header-anchor">#</a> 扩展组件懒加载</h2> <p>内部组件采用()=&gt;import()方式进行引用即可实现组件懒加载</p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/greper/d2-crud-plus/edit/master//d2-crud-plus-docs/guide/extends.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2020-7-16 5:27:26 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/d2-crud-plus/guide/slot.html" class="prev">
        slot自定义
      </a></span> <span class="next"><a href="/d2-crud-plus/guide/dict.html">
        数据字典
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/d2-crud-plus/assets/js/app.920fe806.js" defer></script><script src="/d2-crud-plus/assets/js/2.9f3ba775.js" defer></script><script src="/d2-crud-plus/assets/js/50.5a933b10.js" defer></script>
  </body>
</html>
